package model;

import entities.*;
import product.manager.impl.ProductManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: NGUYEN VAN NHAN
 * Date: 9/21/14
 * Time: 9:11 PM
 * Long Van Soft Solution Sjc.
 * To change this template use File | Settings | File Templates.
 */
public class ProductInfo {
//    private HashMap<String, List<ProductInfo>> productInfoMap = new HashMap<String, List<ProductInfo>>();

    //all product <ProductId, Product>
    private HashMap<String, Product> productMap;

    //<ProductId, ImagesList>
    private HashMap<String, List<Image>> productImageMap;

    // <ProductId, ProductSocialList
    private HashMap<String, List<ProductSocial>> productSocialMap;

    // <MemberId, ProductList>
    private HashMap<String, List<Product>> memberProductMap;

    private HashMap<String, Member> memberMap;

//    public List<Product> getProductByMemberId(String membetId){
//        List<Product> productList;
//        return null;
//    }

    private HashMap<String, Product> loadProductMap(){
        ProductManager productManager = new ProductManager();
        List<Product> productList = productManager.getAllProduct();
        for (Product product: productList){
            productMap.put(product.getProductId(), product);
        }
        return productMap;
    }

    private HashMap<String, List<Product>> loadMemberProductMap(){
        for (String memberId: memberMap.keySet()){
            memberProductMap.put(memberId, getProductListByMemberId(memberId));
        }
        return memberProductMap;
    }

    private List<Product> getProductListByMemberId(String memberId){
        List<Product> productList = new ArrayList<Product>();
        for (Product product: productMap.values()){
            if(memberId.equals(product.getMemberId()))
                productList.add(product);
        }
        return productList;
    }

    public List<ProductSocial> getProductSocialByProductId(String ProductId){
        return null;
    }

    public List<ProductSocial> getProductSocialByMemberIdAndProductId(String memberId, String productId){
        return null;
    }

    public int getCountViewByProductId(String productId){
         List<ProductSocial> productSocialList = productSocialMap.get(productId);
        int count = 0;
        for (ProductSocial productSocial: productSocialList){
            View view = getViewById(productSocial.getViewId());
            count+=view.getCount();
        }
        return count;
    }

    public View getViewById(String viewId){

        return null;
    }


}
